<?php
/**************************************************
* PluginLotto.com                                 *
* Copyrights (c) 2005-2010. iZAP                  *
* All rights reserved                             *
***************************************************
* @author iZAP Team "<support@izap.in>"
* @link http://www.izap.in/
* @version {version} $Revision: {revision}
* Under this agreement, No one has rights to sell this script further.
* For more information. Contact "Tarun Jangra<tarun@izap.in>"
* For discussion about corresponding plugins, visit http://www.pluginlotto.com/pg/forums/
* Follow us on http://facebook.com/PluginLotto and http://twitter.com/PluginLotto
 */

$entity = $vars['entity'];
?>
<div class="poll_style">
  <?php
// loop for calculating result percentage of all options
  for($i = 1; $i <= $entity->total_options; $i++) {
    $voted_option = 'voted_' . $i;
    $voted_result = izap_calculate_percentage($entity->$voted_option, $entity->total_votes);
    $width[$i] = $voted_result;
  }
  $max = max($width);  //calculating maximum width

  // Short circut for the value precisions due to round
  $total = array_sum($width);
  $difference = (100 - $total);
  $key = array_search($max, $width);
  $width[$key] = $width[$key] + $difference;

  // loop for creating bars according to result
  for($i = 1; $i <= $entity->total_options; $i++) {
    $option_dec = 'option_'.$i;
    $voted_option = 'voted_' . $i;
    $per_sign = ' (' . (float)$width[$i] . '%)';

    if($key == $i) { // checking if max width greater for diffrentiate color of bar
      $class = 'higest_poll_bar';
    }else {
      $class = 'poll_bar';
    }
    
    echo '<b>' . $entity->$option_dec . '</b><br />';
    echo '<div class="'.$class.'" style="width:'.$width[$i].'%;background-color:'.$color.';color:'.$font_color.';">' . $per_sign . '</div>';
    echo '<div class="clearfloat"></div>';
  }
  ?>
</div>
<?php
echo '<div class="total_votes">'.elgg_view('output/total_votes',array('entity' => $entity)).'</div>';